<?php

namespace app\common\model;

class Coral extends BaseModel
{
    public function getCoralPassedDays($member_id)
    {
        $entry = $this->where(['member_id' => $member_id])->order('id asc')->field('to_days(now())-to_days(create_time) as days')->find();
        if (!empty($entry)) {
            return $entry['days'] + 1;
        }
        return -1;
    }

    public function getRankList($status = 0)
    {
        $sql = '
select t.*,m.nickname,m.avatar from (select sum((to_days(now()) - to_days(coral.create_time)+1)) as days,member_id from coral 
group by member_id order by days desc)
 t inner join  member m on m.id=t.member_id where auth_status = ' . $status . ' limit 0,50';
        return $this->query($sql);
    }
}

